package com.example.system.controller.sysuser;

import com.example.common.core.domain.Result;
import com.example.system.domain.sysuser.dto.LoginDTO;
import com.example.system.domain.sysuser.dto.SysUserSaveDTO;
import com.example.system.domain.sysuser.vo.SysUserVO;
import com.example.system.service.sysuser.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 23050
 * @version 1.0
 * @description: 管理后台用户类
 * @date 2025/1/19 18:56
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    /**
     * @author 23050
     * @description:  登录
     * @date: 2025/1/19 20:19
     * @param loginDTO:接受体
     * @return null
     */
    @PostMapping("/login")
    @Operation(summary = "登录",description = "根据用户名密码登录")
    @ApiResponse(responseCode = "1000",description = "登录成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙，请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户或密码错误")
    public Result login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }


    /**
     * @author 23050
     * @description: 注销登录   -- 从redis中删除这个jwt即可
     * @date: 2025/2/16 15:35
     * @return com.example.common.core.domain.Result
     * delete   /system/sysUser/logout
     */
    @DeleteMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token){
        return sysUserService.logout(token);
    }


    /**
     * @author 23050
     * @description:  从redis中获取用户的信息
     * @param token：用户签发的token
     * @return com.example.common.core.domain.Result<java.lang.Void>
     * 接口地址：/system/sysUser/info
     */
    @GetMapping("/info")
    public Result info(@RequestHeader("Authorization") String token){
        return sysUserService.info(token);
    }





    //管理员的增删改查
    //请求地址：sysuser/add
    //请求方法：post
    @PostMapping("/add")
    @Operation(summary = "新增系统管理员",description = "根据用户输入新增")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙，请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        return sysUserService.add(sysUserSaveDTO);
    }


    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户")
    @Parameters(value = {
            @Parameter(name = "userId",in = ParameterIn.PATH,description = "用户ID")
    })
    @ApiResponse(responseCode = "1000",description = "删除成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙")
    @ApiResponse(responseCode = "3101",description = "用户不存在")
    public Result<Void> delete(@PathVariable Long userId){
        return null;
    }



    @GetMapping("/detail")
    @Operation(summary = "用户详情",description = "根据查询条件查询用户详情")
    @Parameters(value = {
            @Parameter(name = "userId",in = ParameterIn.QUERY,description = "用户ID"),
            @Parameter(name = "sex",in = ParameterIn.QUERY,description = "用户性别")
    })
    @ApiResponse(responseCode = "1000",description = "成功获取用户信息")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙")
    @ApiResponse(responseCode = "3101",description = "用户不存在")
    public Result<SysUserVO> detail(@RequestParam(required = true) Long userId,
                                    @RequestParam(required = false) String sex){
        return null;
    }







}
